function Node(data, left, right) {
    this.data = data;
    this.left = left;
    this.right = right;
}

Node.prototype = {
    show: function() {
        console.log(this.data);
    }
}

function Tree() {
    this.root = null;
}

Tree.prototype = {
    insert: function(data) {
        var node = new Node(data, null, null);
        if (!this.root) {
            this.root = node;
            return;
        }
        var current = this.root;
        var parent = null;
        while (current) {
            parent = current;
            if (data < parent.data) {
                current = current.left;
                if (!current) {
                    parent.left = node;
                    return;
                }
            } else {
                current = current.right;
                if (!current) {
                    parent.right = node;
                    return;
                }
            }

        }
    }
}

var bTree = new Tree();
bTree.insert(3);
bTree.insert(8);
bTree.insert(1);
bTree.insert(2);
bTree.insert(5);
bTree.insert(7);
bTree.insert(6);
bTree.insert(0);


/*

            3
          /   \
         1     8
        / \   / 
       0   2  5 
              \
               7
              /
             6  

*/

export { Node, Tree, bTree }